In [39]:
import matplotlib.pyplot as plt
import numpy as np
import scipy as sc
import scipy.io as SIO
from scipy import misc
import skimage as ski
import os
from prettyprint import pp
import h5py
%matplotlib inline
import pylab
pylab.rcParams['figure.figsize'] = (10.0, 8.0)
from datetime import datetime
In [40]:
data_path = 'E:/University Central/IPLab/ELM Edge Detection/BSR/BSDS500/data'
images_path = os.path.join(data_path, 'images')
gt_path = os.path.join(data_path, 'groundTruth')
sub_folders = ['test', 'train', 'val']
In [8]:
# pp(os.listdir(gt_path + '/test'))
f_mat = os.path.join(gt_path + '/test', os.listdir(gt_path + '/test')[-1])
print f_mat
In [9]:
# mat_data_hdfs = h5py.File(f_mat, 'r')['/']
mat_data = sc.io.loadmat(f_mat)
print os.path.basename(f_mat)
In [12]:
gts = SIO.loadmat(f_mat)
gts = gts["groundTruth"].flatten()
bnds = [b["Boundaries"][0, 0] for b in gts]
segs = [gt["Segmentation"][0, 0] for gt in gts]
overall = np.zeros(bnds[0].shape)
print bnds[0].shape
In [13]:
plt.imshow(bnds[0], cmap='gray')
plt.show()
plt.imshow(bnds[0].transpose(), cmap='gray')
plt.show()
In [14]:
for bnd in bnds:
overall += bnd
plt.imshow(overall, cmap='gray')
plt.show()
In [15]:
for seg in segs:
plt.imshow(seg)
plt.show()
In [16]:
size_set = set()
path = os.path.join(images_path, sub_folders[0])
for im in os.listdir(path):
img_addr = os.path.join(path, im)
img = misc.imread(img_addr)
size_set.add(img.shape)
In [17]:
print size_set
In [18]:
path = os.path.join(images_path, sub_folders[0])
for im in (os.listdir(path))[9:10]:
print im
img_addr = os.path.join(path, im)
img = misc.imread(img_addr)
plt.imshow(img)
plt.show()
print img.shape
now = datetime.now()
img = img.transpose((2,0,1))
print 'transforming took ', (datetime.now() - now)
for i in xrange(3):
plt.imshow(img[i,:,:], cmap='gray')
plt.show()
Testing the data loading implementation
In [43]:
from bsds500 import load_data
from datetime import datetime
now = datetime.now()
data = load_data(['train', 'val', 'test'])
print 'loading all data took ', (datetime.now() - now)
len(data)
Out[43]:
In [36]:
boundaries = []
for mat in os.listdir(gt_path + '/val'):
matdir = os.path.join(gt_path + '/val', mat)
gts = SIO.loadmat(matdir)
gts = gts["groundTruth"].flatten()
bnds = [b["Boundaries"][0, 0] for b in gts]
bnd_cnt.append(len(bnds))
boundaries.append(bnds)
plt.hist(bnd_cnt)
plt.show()
print len([a for a in bnd_cnt if a == 6])
In [38]:
for n in range(10):
print n, len([bnd for bnd in boundaries if len(bnd) == n])
In [32]:
bnd8 = [bnd for bnd in boundaries if len(bnd) == 8]
In [33]:
for bnd in bnd8[1]:
plt.imshow(bnd, cmap='gray')
plt.show()
In [ ]: